<?php
ob_start();
session_start();
include('config.inc.php');
	//เก็บค่าหน้าที่มาสู่หน้าเข้าสู่ระบบ
	$cur_page = $_SESSION['cur_page'];
	if($cur_page == ""){
		$cur_page = "index.php";
		}
	$user = $_POST['user'];
	$passwd = $_POST['passwd'];
	
	$_SESSION['fcr_id'] = session_id();
	$_SESSION['fcr_user'] = $user;
	$parameters = array('email'=> $user ,'pwd'=> $passwd);
	
	$client = new SoapClient('http://10.30.3.95:8080/ConnLdapService/ConnLdap?wsdl', array('trace' => 1));
	
	$client->__soapCall("connLdap", array($parameters));
	
	$ret = $client->__getLastResponse();
	
	//$ret = 1;
	if($ret){
		$_SESSION['sess_id'] = session_id();
		$_SESSION['sess_user'] = $user;
		$_SESSION['sess_passwd'] = $passwd;
		$_SESSION['sess_status'] = "active";
		$_SESSION['sess_flag'] = $arr['flag'];
		$sql = "select * from users where username='$user'";
		$result = mysql_query($sql);
		@$num = mysql_num_rows($result);
		if($num != 0 && $arr = mysql_fetch_array($result)){
			//$_SESSION['sess_id'] = session_id();
			//$_SESSION['sess_user'] = $arr['username'];
			//$_SESSION['sess_passwd'] = $arr['password'];
			//$_SESSION['sess_status'] = "active";
			$_SESSION['sess_flag'] = $arr['flag'];
			//header('Location: '.$cur_page);
	
		}else{
			//$msg = "คุณใส่รหัสผ่านไม่ถูกต้อง";
			//header("Location: login.php?msg=$msg&page=$page");
			$_SESSION['sess_flag'] = "1";
		}
		mysql_close($connect);		
		header('Location: '.$cur_page);
		
	}else{
		$msg = "คุณใส่รหัสผ่านไม่ถูกต้อง";
		header("Location: login.php?msg=$msg&page=$page");		
		exit;
	}
	

?>